//
//  XLEmoticonPageView.swift
//  XLVeibo
//
//  Created by macbook on 16/7/5.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

let pageViewCellID = "pageViewCell"

class XLEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
}
    
    
    func setupUI(){
    backgroundColor = UIColor.whiteColor()
    self.delegate = self
    self.dataSource = self
        
        //注册cell
        registerClass(XLEmoticCollectionViewCell.self, forCellWithReuseIdentifier: pageViewCellID)
        
        //创建flowLayout
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        layout.itemSize = CGSize(width: KScreenW, height: 216 - 37)
        
        //设置间距
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        
        //设置滚动方向
        layout.scrollDirection = .Horizontal
        
        
    }
    
}


extension XLEmoticonPageView:UICollectionViewDelegate,UICollectionViewDataSource{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return XLEmoticonShardTools.shardTools.allEmotion.count
    }

    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return XLEmoticonShardTools.shardTools.allEmotion[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(pageViewCellID, forIndexPath: indexPath) as! XLEmoticCollectionViewCell
        
//          cell.indexPath = indexPath  显示多少第几组第几页
       
        //给cell赋值
        cell.emoticons = XLEmoticonShardTools.shardTools.allEmotion[indexPath.section][indexPath.item]
      
        
        return cell
    }
}







